package com.neusoft.dibuy.combiner;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
    final IntWritable one = new IntWritable(1);
    Text key_out = new Text();

    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, IntWritable>.Context context) throws IOException, InterruptedException {

        String string = value.toString();
        for (String word : string.split(" ")) {
            key_out.set(word);
            context.write(key_out, one);
        }
    }
}
